package com.tyd.cams.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.tyd.cams.MainsActivity;
import com.tyd.cams.R;
import com.tyd.cams.StartActivity;
import com.tyd.cams.TzggActivity;
import com.tyd.cams.entity.SkTzgg;
import com.xuexiang.xui.adapter.simple.ViewHolder;

import java.util.List;

import static com.xuexiang.xui.XUI.getContext;

/**
 * @author: TYD
 * @作者: 唐YaDong
 * @date: 2021/3/7 4:51
 * @description：TzggAdapter
 * @描述：TzggAdapter 通知公告ListView适配器
 * @版本：1.0
 */

public class TzggAdapter extends BaseAdapter {
    private List<SkTzgg> list;
    private LayoutInflater layoutInflater;

    public TzggAdapter(Context context, List<SkTzgg> list) {
        this.layoutInflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        Log.e("公告Size", "list.size()--" + list.size());
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.tzgg_list_menu, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        SkTzgg skTzgg = list.get(position);
        viewHolder.title.setText(skTzgg.getTitle());
        viewHolder.context.setText("* " + skTzgg.getContext());
        viewHolder.time.setText("发布于：" + skTzgg.getTime());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "正在加载 " + skTzgg.getTitle(), Toast.LENGTH_SHORT).show();
                Intent intent = new Intent();
                intent.putExtra("href", skTzgg.getHref());
                intent.setClass(getContext(), TzggActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
                getContext().startActivity(intent);
            }
        });
        return convertView;
    }
 /*   private void re_xm(String Url) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.XM");
        intent.putExtra("xm",Url);
        getContext().startActivity(intent);

    }*/
    class ViewHolder {
        TextView title;
        TextView context;
        TextView time;

        public ViewHolder(View view) {
            title = view.findViewById(R.id.title);
            context = view.findViewById(R.id.context);
            time = view.findViewById(R.id.time);
        }
    }
}
